﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using System.Web;

namespace YouHP.Pages
{
    public class WebNews:BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected NewsInfo NewsData;
        protected string Alias = "优医网友";
        protected int CommentCount;
        protected NewsComment NewsComment = new NewsComment();
        protected List<NewsInfo> NewsList = new List<NewsInfo>();
        protected List<NewsComment> NewsCommentList = new List<NewsComment>();
        protected int DataCount = 0;

        protected void HandleCommon()
        {
            this.AddLocation("版块新闻列表", "");

            int id = RequestTools.GetInt("id", 0);
            if (id <= 0)
            {
                this.AddErrLine("无效的参数 id ！");
                return;
            }
            NewsList = NewsInfoBLL.Instance.GetNewsInfoList(true, 9, 1, out DataCount);
            NewsData = NewsInfoBLL.Instance.GetNewsInfoByID(id);
            NewsCommentList = NewsInfoBLL.Instance.GetNewsCommentList(id);
            CommentCount = NewsInfoBLL.Instance.GetNewsCommentCount(id);
            if (NewsData.Id <= 0)
            {
                this.AddErrLine("该新闻不存在！");
                return;
            }
            this.SetTitle(NewsData.Title);
        }

        protected void HandlePost()
        {
            string userComment = RequestTools.GetFormString("textareaComment");
            if (!string.IsNullOrEmpty(userComment))
            {
                NewsComment.CommentData = userComment;
            }
            else
            {
                return;
            }
            NewsComment.NewsID = NewsData.Id;
            if (!string.IsNullOrEmpty(UserData.UserName))
            {
                NewsComment.Alias = UserData.UserName;
                NewsComment.InsertDateTime = DateTime.Now;
                NewsInfoBLL.Instance.AddNewsComment(NewsComment);
            }
            else
            {
                this.AddErrLine("您尚未登陆！");
                return;
            }
            int id = RequestTools.GetInt("id", 0);
            if (id <= 0)
            {
                this.AddErrLine("无效的参数 id ！");
                return;
            }
            NewsList = NewsInfoBLL.Instance.GetNewsInfoList(true, 9, 1, out DataCount);
            NewsData = NewsInfoBLL.Instance.GetNewsInfoByID(id);
            NewsCommentList = NewsInfoBLL.Instance.GetNewsCommentList(id);
            CommentCount = NewsInfoBLL.Instance.GetNewsCommentCount(id);
            if (NewsData.Id <= 0)
            {
                this.AddErrLine("该新闻不存在！");
                return;
            }
        }

        protected void HandleGet()
        {


        }
    }
}